//
//  ST_PecGroupListCell.swift
//  btvideo
//
//  Created by mac on 2020/5/28.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift
import SwiftyJSON

class ST_PecGroupListCell: UICollectionViewCell,ST_PecGroupshareViewRectProtocol {
    
    func picutreframe_in_content_view() -> CGRect {
        return self.cover_image_view.frame
    }
    
 
    static let width = (ScreenWidth - 15*2 - 10)/2.0
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.contentView.backgroundColor = Color.white
        
        contentView.addSubview(cover_image_view)
        contentView.addSubview(content_label)
        
        
        cover_image_view.snp.makeConstraints { (make) in
            make.top.right.left.equalToSuperview()
        }
        
        
     
        content_label.snp.makeConstraints { (make) in
            make.top.equalTo(cover_image_view.snp.bottom).offset(8)
            make.right.equalToSuperview().offset(-5)
            make.left.equalToSuperview().offset(5)
            make.bottom.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.cornerRadius = 20
        return control
    }()
    
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.numberOfLines = 2
        return control
    }()
 
//    MARK: - Bind Model
    var model = ST_PecGroupListCellModel(fromJson: JSON.null){
        didSet{
            
            
            cover_image_view.pin_setImage(from: model.content.compress_image().url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            content_label.attributedText = model.remarkAttri
            
        }
    }
    
}



class ST_PecGroupListOnlyImageCell: ST_PecGroupListCell {
    
 
    override init(frame: CGRect) {
        super.init(frame: frame)

        
        content_label.snp.removeConstraints()
        
        cover_image_view.snp.remakeConstraints { (make) in
            make.top.bottom.right.left.equalToSuperview()
        }
        
        content_label.removeFromSuperview()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}



/**
 共享View 使用
 */
protocol ST_PecGroupshareViewRectProtocol {
    func picutreframe_in_content_view()->CGRect
}
